package day19;

import java.util.ArrayList;
import java.util.List;

public class BankAccount {
    String name;
    String num;
    double balance;
    public BankAccount(String name,String num){
        this.name=name;
        this.num=num;
    }
    public void deposit(double amount){
        if (amount>0){
            balance+=amount;
            System.out.println("存入"+amount+"成功，余额："+balance);
        }else {
            System.out.println("存款金额必须大于0!");
        }
    }

    public void withdraw(double amount){
        if (amount>balance){
            System.out.println("余额不足！");
        }else{
            balance-=amount;
            System.out.println("成功取款"+amount+"元,余额："+balance);
        }
    }

    public double getBalance(){
        return balance;
    }
}
class BankAccountManager{
    List<BankAccount> list=new ArrayList<>();

    public void addAccount(BankAccount account){
        list.add(account);
        System.out.println(account.name+"添加账户成功！");
    }
    public void removeAccount(String accountNumber){
        BankAccount isDel=null;
        for (BankAccount b:list){
            if (b.num.equals(accountNumber)){
                isDel=b;
            }
        }
        list.remove(isDel);
        System.out.println("删除成功！");
    }
    public double getAccountBalance(String accountNumber){
         double balance=0;
         for (BankAccount b:list){
             if (b.num.equals(accountNumber)){
                 balance=b.balance;
             }
         }
         return balance;
    }

    public static void main(String[] args) {
        BankAccountManager manager=new BankAccountManager();
        BankAccount aaa=new BankAccount("张三","001");
        manager.addAccount(aaa);
        aaa.deposit(2000);
        aaa.withdraw(1000);
        double balance=aaa.getBalance();


        manager.removeAccount("003");

        balance=manager.getAccountBalance("1");
        System.out.println("指定id余额："+balance);

        BankAccount bbb=new BankAccount("李四","002");
        manager.addAccount(bbb);
        BankAccount ccc=new BankAccount("王五","003");
        manager.addAccount(ccc);
    }
}